import axios from "@/axios"

/** 
 * 上传图片到oss
 * */
export const uploadaddProduct = (files: FormData) => axios.post("/eduoss/fileoss/uploadMultipleFilesArray2", files, {
    headers: {
        'Content-Type': 'multipart/form-data'
    }
});

/** 
 * 添加商品 
 * */
export const addProduct = (ProductsParmas: ProductsParmas) => axios.post("/eduservice/addProduct", ProductsParmas, {
    headers: {
        'Content-Type': 'application/json'
    }
});

// 封装更新商品的 API 请求函数
export const updateProduct = (ProductsParmas: ProductsParmas) => axios.post("/eduservice/updateProduct", ProductsParmas, {
    headers: {
        'Content-Type': 'application/json'
    }
});

// 封装获取商品列表的 API 请求函数
export const getProductList = (
    current: number = 1, // 设置默认值为 1
    limit: number = 10, // 设置默认值为 10
    products?: ProductsParmas // 商品标题参数，可选
): Promise<IResponse<ProductsParmas>> => {
    try {
        let params = { current, limit, products: products || undefined };
        return axios.get("/eduservice/productsPage", { params })
    } catch (error) {
        console.error('获取商品详情失败:', error);
        throw error;
    }
};



// 封装获取商品详情的 API 请求函数
export const getProductDetail = async (productId: number) => {
    try {
        const params = {
            productId
        }
        const response = await axios.get(`/eduservice/sneakersDetail/sneakersDetailInfo`, { params });
        return response;
    } catch (error) {
        console.error('获取商品详情失败:', error);
        throw error;
    }
};


// 封装删除商品的 API 请求函数
export const deleteProduct = async (productId: number) => {
    try {
        const response = await fetch(`/eduservice/deleteProduct/${productId}`, {
            method: 'DELETE'
        });
        const data = await response.json();
        return data;
    } catch (error) {
        console.error('删除商品失败:', error);
        throw error;
    }
};